package com.jlkf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easemob.server.example.api.IMUserAPI;
import com.easemob.server.example.comm.ClientContext;
import com.easemob.server.example.comm.EasemobRestAPIFactory;
import com.easemob.server.example.comm.body.IMUserBody;
import com.easemob.server.example.comm.wrapper.ResponseWrapper;
import com.jlkf.common.rong.models.TokenResult;
import com.jlkf.common.rong.util.RongCloud;
import com.jlkf.service.UserService;
import com.platform.server.response.response.pojo.ReturnData;
@Controller
@RequestMapping("user")
public class UserController {

	@Autowired
	private UserService userService;
	/**
	 * 发送验证码
	 * @param phone
	 * @param type 1注册  2 修改手机号
	 * @param platform 1用户端 2司机端
	 * @return
	 */
	@RequestMapping("sendSMS")
	private Object sendSMS(String  telephone,Integer type,Integer platform){
		return userService.sendSMS(telephone,type,platform);
	}
	/**
	 * 最后一单设置
	 * @param uId
	 * @return
	 */
	@RequestMapping("isLastOrder")
	private Object isLastOrder(Long uId){
		return userService.isLastOrder(uId);
	}
	
	
	/**
	 * 号码是否注册 
	 * @param telephone
	 * @return
	 */
	@RequestMapping("isRegistered")
	private Object isRegistered(String  telephone){
		return userService.isRegistered(telephone);
	}
	/**
	 * 邮箱是否被使用
	 * @param email
	 * @return
	 */
	@RequestMapping("emailIsUse")
	private Object emailIsUse(String  email,Integer language){
		return userService.emailIsUse(email,language);
	}
	/**
	 * 登录
	 * @param json
	 * @return
	 */
	@RequestMapping("login")
	@ResponseBody
	private Object login(@RequestBody String json){
		return userService.login(json);
	}
	/**
	 * 司机登录
	 * @param json
	 * @return
	 */
	@RequestMapping("driverLogin")
	@ResponseBody
	private Object driverLogin(String telephone,String vCode,String auroraAlias,String useEquipment){
		return userService.driverLogin(telephone,vCode,auroraAlias,useEquipment);
	}
	/**
	 * 判断该openId是否已经绑定了手机号 绑定了则直接登录 返回用户信息   没有则他们需跳转到绑定手机号页面
	 * @param email
	 * @return
	 */
	@RequestMapping("facebookLogin")
	private Object facebookIsRegistered(String  openId,Integer language){
		return userService.facebookIsRegistered(openId,language);
	}
	
	/**
	 * 注册
	 * @param json
	 * @return
	 */
	@RequestMapping("registration")
	@ResponseBody
	private Object registration(@RequestBody String json){
		try {
			return userService.registration(json);
		} catch (Exception e) {
			e.printStackTrace();
			return new ReturnData(500, "Wow, that's wrong ");
		}
	}
	/**
	 * 编辑用户信息
	 * @param json
	 * @return
	 */
	@RequestMapping("updateUser")
	@ResponseBody
	private Object updateUser(@RequestBody String json){
		return userService.updateUser(json);
	}
	/**
	 * 我的信息
	 * @param json
	 * @return
	 */
	@RequestMapping("myInformation")
	private Object myInformation(Long uId){
		return userService.myInformation(uId);
	}
	/**
	 *  环信 获取用户对象的头像与昵称
	 * @param uId
	 * @return
	 */
	@RequestMapping("getMyPortraitAndName")
	private Object getMyPortraitAndName(Long uId){
		return userService.getMyPortraitAndName(uId);
	}
	//我的账户统计
	@RequestMapping("myAccount")
	public Object myAccount(Long uId){
		return userService.myAccount(uId);
	}
	/**
	 * 我的银行卡列表
	 * @param uId
	 * @return
	 */
	@RequestMapping("myBrankList")
	public Object myBrankList(Long uId){
		return userService.myBrankList(uId);
	}
	/**
	 * 银行卡免密设置
	 * @param ubId
	 * @return
	 */
	@RequestMapping("setTheDefault")
	public Object setTheDefault(Long ubId,Long uId){
		return userService.setTheDefault(ubId,uId);
	}
	
	/**
	 *  添加银行卡
	 * @param json
	 * @return
	 */
	@RequestMapping("addUserBrank")
	@ResponseBody
	public Object addUserBrank(@RequestBody String json){
		return userService.addUserBrank(json);
	}
	/**
	 * 删除用户银行卡
	 * @param ubId
	 * @return
	 */
	@RequestMapping("deleteUserBrank")
	public Object deleteUserBrank(Long ubId){
		return userService.deleteUserBrank(ubId);
	}
	
	/**
	 * 我的优惠劵[未使用与已使用金额统计]
	 * @param uId
	 * @return
	 */
	@RequestMapping("getMyCoupons")
	public Object getMyCoupons(Long uId,Integer pageNo,Integer pageSize){
		
		return userService.getMyCoupons(uId,pageNo,pageSize);
	}
	/**
	 * 我的已使用优惠劵
	 * @param uId
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("getMyUseCoupons")
	public Object getMyUseCoupons(Long uId,Integer pageNo,Integer pageSize){
		return userService.getMyUseCoupons(uId,pageNo,pageSize);
	}

	
	/**
	 * 首页司机 查询我的车辆 也许存在多个车辆，选择今日开那一辆
	 * @param uId
	 * @return
	 */
	@RequestMapping("getDriverCar")
	public Object getDriverCar(Long uId){
		return userService.getDriverCar(uId);
	}
	/**
	 * 用户更新
	 * @param uId
	 * @param isOnline
	 * @return
	 */
	@RequestMapping("updateDriverOnlineStatus")
	public Object updateDriverOnlineStatus(Long uId,Integer isOnline){
		return userService.updateDriverOnlineStatus(uId,isOnline);
	}
	// 用户端  忘记密码
	@RequestMapping("forgetPassword")
	public Object forgetPassword(String telephone,String vCode,String password,Integer language){
		return userService.forgetPassword(telephone,vCode,password,language);
	}

	//退出登录
	@RequestMapping("exitLogin")
	public Object exitLogin(Long id,Integer isOnline,Integer language){
		return userService.exitLogin(id,isOnline,language);
	}
	
	@RequestMapping("test")
	public Object test(){
		/*AuroraPush.pushTargetForUser("user1517052811761", "dsadada", "andro");
		AuroraPush.pushTargetAlertForUser("user1517052811761", "dsadada","andro");*/
		return new ReturnData(200,"");
	}
	
	@RequestMapping("getRongColud")
	public Object getRongColud(Long uId){
		return userService.getRongColud(uId);
	}
}
